<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta charset="UTF-8">
	<title>新增抵扣卡</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    
<!-- 最新导入 -->
<script type="text/javascript" src="<c:url value='/template/new_muban/js/jquery-min-1.7.js'/>"></script>
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/font.css'/>">
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/xadmin.css'/>">   
<script src="<c:url value='/template/new_muban/lib/layui/layui.js'/>" charset="utf-8"></script> 
<script type="text/javascript" src="<c:url value='/template/new_muban/js/xadmin.js'/>"></script>

 <!-- 富文本编辑器 -->
<script type="text/javascript" charset="utf-8" src="<c:url value='/ue/ueditor.config.js'/>"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/ue/ueditor.all.js'/>"> </script>



<!-- 标签 -->
<link rel="stylesheet" type="text/css" href="<c:url value='/template/lead_into/tags_input/css.css'/>" />
<script src="<c:url value='/template/lead_into/tags_input/tagsinput.js'/>" type="text/javascript" charset="utf-8"></script>
		
	
<style type="text/css">
	/*圆形头像  */
	/* #divcss5{ margin:10px auto}  */
	#divcss5 img{ border-radius:50%} 
	.x-so input.layui-input {
    	width: 150px;
	}
</style>
</head>
<body>
   
     <div class="x-body">
        <form class="layui-form ">
          
          <div class="layui-form-item">
              <label for="username" class="layui-form-label" >
                  <span class="x-red">*</span>卡券名称
              </label>
              <div class="layui-input-inline">
                    <input type="text" id="ct_name" name="ct_name" placeholder="请输入卡券名称" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
           <!-- <div class="layui-form-item" >
		    <label for="L_username" class="layui-form-label">
		    <span class="x-red">*</span>标签设置
		    </label>
		    <div class="layui-input-block">
					 <div class="tagsinput-primary form-group">
			                  <input name="tagsinput" id="tagsinputval" lay-verify="required"
			                  		class="tagsinput" data-role="tagsinput" value="随买随用,特惠,不可退款新增优惠券" placeholder="输入后回车" />
			             
		              </div>
		    </div>
		  </div> -->
          

    
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>到期时间
              </label>
              <div class="layui-input-inline"  >
                 <input class="layui-input" lay-verify="required"   placeholder="截止日" name="end" id="end" readonly>
              </div>
          </div>
 
     
         <%--  
          
          <div class="layui-form-item">
			    <label class="layui-form-label">是否指定门票使用</label>
			    <div class="layui-input-block">
			      <input type="checkbox" name="c_type" lay-skin="switch" lay-filter="power1" lay-text="ON|OFF">
			    </div>
  		  </div>
          
          
           <div class="layui-form-item layui-row">
              <label for="username" class="layui-form-label" >
         指定门票
              </label>
              <div class="layui-input-inline" style="width:50%">
              	<c:forEach	items="${allPromotionByFlagAndStatus}" var="pf">
              		
                    <input type="checkbox" name="t_id" value="${pf.t_id}" title="${pf.t_name}" lay-skin="primary" >
              		<div class="layui-unselect layui-form-checkbox" lay-skin="primary"><span>${pf.t_name}</span><i class="layui-icon layui-icon-ok"></i></div>
              		
              	</c:forEach>
              </div>
          </div> 
           --%>
          
          
          
          
          
          
          <div class="layui-form-item">
              <label for="username" class="layui-form-label" >
             折扣百分制
              </label>
              <div class="layui-input-inline">
                    <input type="username" id="c_num" 
                  autocomplete="off" class="layui-input" placeholder="不设置默认为100"  min="10" max="100"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
              </div>
          </div>
          
           <div class="layui-form-item">
			    <label class="layui-form-label">是否启用</label>
			    <div class="layui-input-block">
			      <input type="checkbox" checked="" name="ct_status" lay-skin="switch" lay-filter="power" lay-text="ON|OFF">
			    </div>
  		  </div>
          
          
           <div class="layui-form-item layui-form-text">
              <label for="desc" class="layui-form-label">
           <span class="x-red">*</span> 折扣说明
              </label>
              <div class="layui-input-block" >
               	<script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
              </div>
           </div> 
          	
         
          <div class="layui-form-item" id="upload_show" ><!--  style="display: none;" -->
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                 添加
              </button>
          </div>
      </form>
    </div>
    <script>
    

    //时间
    layui.use('laydate', function(){
      var laydate = layui.laydate;
      
      //执行一个laydate实例
      laydate.render({
        elem: '#start' //指定元素
        	,type: 'datetime'
      });

      //执行一个laydate实例
      laydate.render({
        elem: '#end' //指定元素
        	,type: 'datetime'
      });
    });
  
    
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          
          var cond = true;
          //监听switch开关
        form.on('switch(power)', function(data){
    	 // console.log(data.elem); //得到checkbox原始DOM对象
    	  console.log(data.elem.checked); //开关是否开启，true或者false
    	 // console.log(data.value); //开关value值，也可以通过data.elem.value得到
    	 // console.log(data.othis); //得到美化后的DOM对象
    	 	cond = data.elem.checked;
    	 //	alert(cond);
    	 	
    	 });  
          
     
          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            
          //优惠券名称
          var ct_name = $("#ct_name").val();
       //   alert("图片路径     :  "+file_url);
    
        //到期时间
          var ct_Invalidtime = $("#end").val();
          //排序
          var ct_zk = $("#ct_zk").val();
         var ct_info =  UE.getEditor('editor').getContent();
          
        //优惠券状态
        var ct_status = 0;
        //是否启用
        if(cond == false){
        	ct_status = 1;
        }
        
   

        if(ct_zk == ''){
        	ct_zk = 100;
        }

        
       /*  var c_ticket_list = $("input:checkbox[name='t_id']:checked").map(function(index,elem) {
            return $(elem).val();
        }).get().join(',');
        
        //判断是否开启指定商品
        var c_type = 0;
        
        //是否启用
        if(cond1 == true){
        	c_type = 1;
        }else{
        	c_type = 0;
        	
        }
        
        if(c_type == 0){
        	//清空
        	c_ticket_list = "";
        }
        
        if(c_ticket_list == null || c_ticket_list == ""){
        	c_type = 0;
        }
        
        console.log(c_ticket_list);
        console.log(c_type);
      */
          var aa = 0;
          //发异步，把数据提交给php
           $.ajax({
               type: "POST",
               async : false, // 注意此处需要yi步  
               url:  "<c:url value='/addCoupon.do'/>",
               data: {"c_title":c_title,"c_price":c_price,"c_pay_money":c_pay_money,"c_btime":c_btime,"c_etime":c_etime,"c_counts":c_counts,"c_xz_count":c_xz_count,"c_flag":c_flag,"c_num":c_num
            		,"c_ticket_list":c_ticket_list,"c_type":c_type   
               },
               success: function(data){
                   if (data == 0) {
                  	 aa = 0;
                   } else  {
                  	 aa = 1;
		           } 
              }
	        });   
          
           if(aa == 0){
               layer.msg('新增失败!',{icon: 2,time:3000});      
               return false;
           }else if(aa == 1){
           	
          	  layer.msg("新增成功", {icon: 6,time:500},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //alert(index);
                    //关闭当前frame
                    parent.layer.close(index);
                    //重新加载父页面
                    parent.location.reload();
                });
           }
         	//禁止页面自动跳转
            return false;
          });
        });
    </script>
    
    
  <script>
		
    $('#easyContainer').easyUpload({
      allowFileTypes: '*.jpg;*.png',//允许上传文件类型，格式';*.doc;*.pdf'
      allowFileSize: 1*1024,//允许上传文件大小(KB)
      selectText: '选择图片',//选择文件按钮文案
      multi: false,//是否允许多文件上传
      multiNum: 1,//多文件上传时允许的文件数
      showNote: true,//是否展示文件上传说明
      note: '提示：图片最大支持1M，支持格式为jpg、png,最佳尺寸720*270,请耐心等待上传完成!',//文件上传说明    提示：最多上传5个文件，支持格式为doc、docx、pdf、jpg、png、mp4
      showPreview: true,//是否显示文件预览
      url: '<%=request.getContextPath()%>/toQiNiu.do',//上传文件地址
      fileName: 'file',//文件filename配置参数
     /*  formParam: {
        token: $.cookie('token_cookie')//不需要验证token时可以去掉
      }, */
      //formParam：文件filename以外的配置参数，格式：{key1:value1,key2:value2}
   /*    formParam:{
    	  o_order_id : $(".ziz").val()
      }, */
      timeout: 30000,//请求超时时间
      okCode: 200,//与后端返回数据code值一致时执行成功回调，不配置默认200
     // datatype:'json',
      successFunc: function(res) {
    	 // alert(res);
        console.log('成功回调', res.type);
        
        $("#file_url").val(res.file_url);
     //   layer.msg("上传成功", {icon: 6,time:2000});
      //  alert("上传成功");
     //   $("#upload_show").css('display','block');//显示
      },//上传成功回调函数
      errorFunc: function(res) {
    	  layer.msg("上传失败", {icon: 2,time:2000});
    	 //alert("上传失败");
    	           
    	  //alert(res.okCode);
        //console.log('失败回调', res);
      },//上传失败回调函数
      deleteFunc: function(res) {
        console.log('删除回调', res);
      }//删除文件回调函数
    });
    
    
    
    
  
  </script>
  <!-- 标签input -->
<script type="text/javascript">
function getinput(){
	alert($('#tagsinputval').val());
}     
</script>    
<!-- 小数验证 -->
<script type="text/javascript">
//小数验证
function clearNoNum(obj){  
    //修复第一个字符是小数点 的情况.  
    if(obj.value !=''&& obj.value.substr(0,1) == '.'){  
        obj.value="";  
    }  
    obj.value = obj.value.replace(/^0*(0\.|[1-9])/, '$1');//解决 粘贴不生效  
    obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
    obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的       
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");      
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数       
    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
        if(obj.value.substr(0,1) == '0' && obj.value.length == 2){  
            obj.value= obj.value.substr(1,obj.value.length);      
        }  
    }      
}      
  

</script>
<!-- ue初始化 -->
<script type="text/javascript">
			var ue = UE.getEditor('editor',{
				autoFloatEnabled:false,
				toolbars: [[
		    		'source','bold', 'italic',  'removeformat', 'formatmatch', 'autotypeset','selectall', 'cleardoc', 
		           'lineheight', '|','fontfamily', 'fontsize', 'forecolor', 'backcolor','|',
		            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|','insertimage', 'emotion', 'insertvideo'
		        ]]
			});
			
		</script>

      
  </body>
</html>